//
//  HMVistorTableViewController.swift
//  weibo
//
//  Created by 杨念川 on 16/8/30.
//  Copyright © 2016年 杨念川. All rights reserved.
//

import UIKit

class HMVistorTableViewController: UITableViewController,HMVistorViewDelegate {
    //判断是否登录
    var userLogin = false
    //
    override func loadView() {
        //判断是否登录，加载不同的View
        if userLogin {
            super.loadView()
        }else {
            setupView()
            //presentVC()
        }
    }
    
    //定义一个闭包,执行操作
    let loginclosure = {
        
        //presentVC()
        print("我点击了闭包")
    }
    //实现代理方法
    func visitorViewWillLogin() {
        presentVC()
    }
    //跳转控制器
    private func presentVC() {
        // 初始化一个导航控制器
        let vc = HMNavigationController(rootViewController: HMOAuthController())
        // modal控制器
        self.present(vc, animated: true, completion: nil)
    }
    //加载view
    func setupView() {
        //创建
        let v = self.visitorView
        //v.loginClosure = loginclosure
        //v.backgroundColor = UIColor.rg
        self.view = v
    }
    // MARK: - 懒加载控件
    lazy var visitorView: HMVistorView = {
        let visitorView = HMVistorView()
        //实现代理属性
        visitorView.delegate = self
        return visitorView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: nil, action: nil)
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(login))
        
    }
    //navigationBar的右侧按钮实现
    func login() {
        presentVC()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
